package com.desuntech.utils
{
	import C4D.kbmMWConnection;
	
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	public class ServerDatetime
	{
		private static var _sd:ServerDatetime;
		private static var _dt:Date;
		private static var _service:Amf3Service;
		
		public static function getInstance():ServerDatetime {
			if (_sd == null)
				_sd = new ServerDatetime();
			return _sd;
		}
		
		public function initAppDT(conn:kbmMWConnection):void {
			_service = new Amf3Service();
			_service.connection = conn;
			_service.getServerDatetime(onGetServerDT);
			var timer:Timer = new Timer(10000);
			timer.addEventListener(TimerEvent.TIMER, getServerDT);
			timer.start();
		}
		
		private function getServerDT(evt:TimerEvent):void {
			_service.getServerDatetime(onGetServerDT);
		}
		
		private function onGetServerDT(dt:Date):void {
			_dt = dt;
		}
		
		public function get currentDate():Date {
			return _dt;
		}
	}
}